﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlasmaMes.Services
{
    public enum Log_Type
    {
        Info,
        Warning,
        Error
    }
    public  class LogService
    {

        private static LogService instance;


        private static readonly object locker = new object();   


        private LogService() { }


        public static LogService Instance
        {
            get 
            { 
                if (instance == null)
                {
                    lock (locker)
                    {
                        instance = new LogService();
                    }
                }

                return instance; 
            }
        }


        public delegate void UpdateRichTextBox(string msg, Log_Type log_Type);
        public static event UpdateRichTextBox UpdateRichTextBoxEvent;

        public void LogError(string msg)
        {
            AddLog(msg, Log_Type.Error);
        }
        public void LogWarning(string msg)
        {
            AddLog(msg, Log_Type.Warning);
        }
        public void LogInfo(string msg)
        {
            AddLog(msg, Log_Type.Info);
        }


        private void AddLog(string msg, Log_Type logType)
        {
            UpdateRichTextBoxEvent?.Invoke(msg, logType);
        }





    }
}
